define(['zepto', 'butterfly/view','../../bsl',
    'text!./nativeui.html'
], function($, View, bsl, nativeui) {
    var me = null;

    var view = View.extend({
        events: {

            // ！！！！ 由于 引入 touch.js 后，tap事件会变成双击，所以 本页面内不能使用tap，用click代替。
            "tap #openDoc" : "openDoc",
            "tap #back" : "back",
            "tap .pickDate" : "pickDate",
            "tap .pickTime" : "pickTime",
            "tap .showWaiting" : "showWaiting",
            "tap .showAlert" : "showAlert",
            "tap .showConfirm" : "showConfirm",
            "tap .showPrompt" : "showPrompt",
            "tap .showActionSheet" : "showActionSheet",
            "tap .showToast" : "showToast",

      
        },
        render: function() {
            me = this;
        },

        onShow: function() {

            // 绑定自定义事件 滑动切换日历等           


        },
               pickDate: function () {
            outSet( "打开系统日期选择框：");
            var dDate=new Date();
            dDate.setFullYear(2014,0,1);
            var minDate=new Date();
            minDate.setFullYear(2010,0,1);
            var maxDate=new Date();
            maxDate.setFullYear(2016,11,31);
            console.info( "[date] "+dDate );
            console.info( "[minDate] "+minDate );
            console.info( "[maxDate] "+maxDate );
            bsl.nativeUI.pickDate( function(e) {
                var d=e.date;
                console.info( "选择的日期："+d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate() );
            },function(e){
                outSet( "未选择日期："+e.message );
            },{title:"请选择日期",date:dDate,minDate:minDate,maxDate:maxDate});
        },
        pickTime:function () {
            outSet( "打开系统时间选择框：");
            var dTime=new Date();
            dTime.setHours(6,0);
            console.info( "[time] "+dTime );
            bsl.nativeUI.pickTime(function(e){
                var d=e.date;
                console.info( "选择的时间："+d.getHours()+":"+d.getMinutes() );
            },function (e){
                outSet( "取消选择时间！" );
            },{title:"请选择时间",is24Hour:true,time:dTime});
        },
        showWaiting:function (){
            var w=bsl.nativeUI.showWaiting("　　 请等待...　　 \n5");
            var n=5;
            var t=setInterval(function(){
                n--;
                w.setTitle("　　 请等待...　　 \n"+n);
                if(n<=0){
                    clearInterval(t);
                    w.close();
                }
            },1000);
        },
        showAlert:function (){
            outSet( "弹出系统提示对话框：" );
            bsl.nativeUI.alert("请注意！\n我是系统提示框",function(e){
                var i=e.index;
                if(i<0){
                    console.info( "按\"返回\"键关闭提示框！" );
                }else{
                    console.info( "提示框已关闭！" );   
                }
            },"nativeUI","好");
        },
        showConfirm:function (){
            outSet( "弹出系统确认对话框：" );
            var bts=["是","否","取消"];
            bsl.nativeUI.confirm("请确认是否弹出系统框？",function(e){
                var i=e.index;
                console.info( "按\""+((i>=0)?bts[e.index]:"返回")+"\"关闭！" );
            },"nativeUI",bts);
        },
        showPrompt:function (){
            outSet( "弹出系统输入对话框：" );
            var bts=["确认","取消"];
            bsl.nativeUI.prompt("请输入你的姓名",function(e){
                var i=e.index;
                console.info( "按\""+((i>=0)?bts[e.index]:"返回")+"\"关闭："+e.value );
            },"nativeUI","姓名",bts);
        },
        showActionSheet:function (){
            outSet( "弹出系统选择按钮框：" );
            var bts=[{title:"警告",style:"destructive"},{title:"按钮1"},{title:"按钮2"},{title:"按钮3"}];
            bsl.nativeUI.actionSheet({title:"ActionSheet标题",cancel:"取消",buttons:bts},
                function(e){
                    console.info( "选择了\""+((e.index>0)?bts[e.index-1].title:"取消")+"\"");
                }
            );
        },
        showToast:function (){
            bsl.nativeUI.toast("您好！正在使用HBuilder开发应用！",{duration:"long"});
        },
          back : function(e){
            window.history.go(-1);
        },
        openDoc:function(){
             window.butterfly.navigate('com.no5.cordovademo/doc/nativeUI', {
                trigger: true
            });


        },
        
    
             
            });
    return view;
});
